import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),k = in.nextInt();
        long[] a = new long[n+1];
        for(int i=1;i<=n;i++) {
            a[i] = in.nextLong();
        }
        long[][] dp = new long[n+1][k];
        //初始化
        for(int i=0;i<=n;i++) {
            for(int j=0;j<k;j++) {
                dp[i][j] = (long)-1e16;
            }
        }
        dp[0][0] = 0;

        for(int i=1;i<=n;i++) {
            for(int j=0;j<k;j++) {
                dp[i][j] = Math.max(dp[i-1][j],dp[i-1][(int)((j-a[i]%(long)k+(long)k)%(long)k)]+a[i]);
            }
        }

        if(dp[n][0]>0) System.out.println(dp[n][0]);
        else System.out.println(-1);
    }
}